//
//  COMineHeadTableCell.swift
//  CocoProject
//
//  Created by Vill on 2023/11/8.
//

import UIKit

class COMineHeadTableCell: UITableViewCell {
    
    @IBOutlet weak var balanceLbl: UILabel!
    
    @IBOutlet weak var iconBg: UIView!

    @IBOutlet weak var icon: UIImageView!
    
    @IBOutlet weak var nameLbl: UILabel!
    
    @IBOutlet weak var idLbl: UILabel!
    
    @IBOutlet weak var rechargeContain: UIImageView!
    
    static let reusedID = "COMineHeadTableCell"
    public func cellWithTableView(_ tableView:UITableView) -> COMineHeadTableCell{
        var cell:COMineHeadTableCell! = tableView.dequeueReusableCell(withIdentifier: COMineHeadTableCell.reusedID) as? COMineHeadTableCell
        if cell == nil {
            cell = (Bundle.main.loadNibNamed("COMineHeadTableCell", owner: nil, options: nil)?.first as! COMineHeadTableCell)
        }
        return cell!
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        self.iconBg.addGradientBorder(colors: [UIColor.colorWithHex("#7038FF"),UIColor.colorWithHex("#FF3DE1")], cornerRadius: 44)
                
        self.icon.layer.cornerRadius = 39
        self.icon.contentMode = .scaleAspectFill
        self.icon.layer.masksToBounds = true
        
        let model = COUserInfoManager.shared.curUser
        self.balanceLbl.text = "\(model?.userResponse.balance ?? 0)"
        self.icon.sd_setUrlImage(model?.userResponse.profilePhoto, placeholder: KImaged("coco_icon_holder"))
        self.nameLbl.text = model?.userResponse.nickName
        self.idLbl.text = "ID:\(model?.userResponse.userId ?? "")"
        self.rechargeContain.addTap {[weak self] ges in
            self?.viewController()?.navigationController?.pushViewController(COBalanceController(), animated: true)
        }
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }
    
    @IBAction func editAction(_ sender: UIButton) {
        self.viewController()?.navigationController?.pushViewController(COEditProController(), animated: true)
    }
    
}
